package mega.privacy.android.app.textEditor

import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
import androidx.navigation3.runtime.EntryProviderScope
import androidx.navigation3.runtime.NavKey
import mega.privacy.android.navigation.contract.FeatureDestination
import mega.privacy.android.navigation.contract.NavigationHandler
import mega.privacy.android.navigation.contract.TransferHandler
import mega.privacy.android.navigation.contract.transparent.transparentMetadata
import mega.privacy.android.navigation.destination.LegacyTextEditorNavKey

fun EntryProviderScope<NavKey>.legacyTextEditorScreen(
    removeDestination: () -> Unit,
) {
    entry<LegacyTextEditorNavKey>(
        metadata = transparentMetadata()
    ) { key ->
        val context = LocalContext.current
        LaunchedEffect(Unit) {
            val intent = TextEditorActivity.createIntent(
                context = context,
                nodeHandle = key.nodeHandle,
                mode = key.mode,
                nodeSourceType = key.nodeSourceType,
                fileName = key.fileName,
            )
            context.startActivity(intent)

            // Immediately pop this destination from the back stack
            removeDestination()
        }
    }
}
